<?php
/**
 * Created by PhpStorm.
 * User: yanggang
 * Date: 2018/9/2
 * Time: 上午10:52
 */

namespace app\common\model;


use think\Model;

class BaseModel extends Model
{

    public function updateMax($id,$data){
        if($id>0){
            $info = self::get($id);
            if(isset($info['has_del']) && $info['has_del']==1)$info=array();
            if(!empty($info)){
                $updatedata = array();
                foreach($data as $k =>$v){
                    if($v!=$info[$k])$updatedata[$k] = $v;
                }
                if(!empty($updatedata)){
                    $pk = $this->getPk();
                    $where[$pk] = $id;
                    self::update($updatedata,$where);
                    return $id;
                }else{
                    return $id;
                }
            }
        }
        unset($data[$this->getPk()]);
        return $this->insertGetId($data);
    }
}